package bdpan

import (
	"awesomeProject/KaedeCrawler/modules"
	"log"
)

var PanLinks []string

/**
  Work() contains three modules:
     1. Download from the url
     2. Parse the string downloaded
     3. handle the data parsed (output,savefile etc.)
  My design is to avoid handling data in engine
  in order to make the program more extendable
*/

func Work(url string) modules.WorkResult {
	body := modules.Download(url)
	urls := GetUrl(body)
	links := GetPanLink(body)
	var result modules.WorkResult
	//var reqs []engine.Request
	for _, u := range urls {
		result.Requests = append(result.Requests, modules.Request{
			Url:    u,
			Worker: Work,
		})
	}
	for _, link := range links {
		result.Items = append(result.Items, link)
	}
	return result
}

func HandleResult(items []interface{}) {
	for i := range items {
		PanLinks = append(PanLinks, string(i))
		log.Printf("Got Link: %s\n", string(i))
	}
}

func AllDone() {
	log.Printf("Program ended. %d links has been founded.\n", len(PanLinks))
}
